|
|
 |
|
|
|
|
Printer.TextHeight(next_word) _
> bottom_margin _
Then ' Start a new page. Printer.NewPage
Printer.CurrentX = left_margin
Printer.CurrentY = top_margin
End If
End If
' Now print the word. The ; makes the ' Printer not move to the next line. Printer.Print next_word & " ";
Loop
' Finish the paragraph by ending the line.
Printer.Print
Loop
End Sub |
|
|
|
|
|
|
|
|
Modern high-quality applications allow the user to preview a printout before printing it. You can provide a print preview by drawing all the printout's commands into a picture box and then displaying it to the user. |
|
|
|
|
|
|
|
|
Unfortunately, producing high-resolution printouts usually requires a lot of code. Generating a print preview requires that you duplicate all of that code. This gives you even more code to program and debug. If you later make changes to the printout code, you have to be sure to make exactly the same changes to the preview code, or the print preview will not look like the final printout. |
|
|
|
|
|
|
|
|
One solution to this potential source of errors is to create a single printing routine that generates both the preview and the final printed output. This routine takes as a parameter a reference to the object on which it should print. |
|
|
|
|
|
|
|
|
To display a print preview, the program passes this routine a reference to a picture box. To produce a printout, the program passes it a reference to the Printer object. After the routine finishes, the program executes the printer's EndDoc method to send the printout to the physical printer. |
|
|
|
|
|
|
|
|
Example program ObjPrint, shown in Figure 5.3, uses this technique to draw a diamond on its form or on the printer. Select the File menu's Print command to print the diamond. |
|
|
|
|
|
|
|
|
The following code shows how program ObjPrint works. The DrawPicture subroutine draws a diamond shape onto the object it is passed as a parameter. |
|
|
|
|
|
|
|
|
The form's Paint event handler clears the form and then uses DrawPicture to display the diamond on the form. |
|
|
|
|
|